<?php
$pPageIsPublic = false;
include '../_common.php';


$pTitle   = 'New Banner';
$pButton  = 'Save';
$action   = 'add';
$objPic = new Picture();

if ($_GET['id']) {	
	$id 	  = intval($_GET['id']);
	$objPic ->setUid($id);
	if ($objPic ->load()) {
		$_SESSION['temp_id'] = $objPic ->id;
		$pTitle  = 'Edit Banner';
		$pButton = 'Update';
		$action  = 'edit';
	}
}

if ($_GET['action']== 'del') {
	if ($objPic ->isLoaded()) {
		$objPic ->removeImage('path');
		$message = "Banner has been deleted.";
	}
		
}

if (isset($_POST['submit'])) {
	$objPic ->setAuto($_POST);
	$objPic ->uploadImage('ifile', 'path'); 
			
	             
	if ($_POST['action'] == 'edit') {
		$objPic ->getConnection();
		$objPic ->setUid(intval($_SESSION['temp_id']));
		$objPic ->update();
		$msg = "msg=Banner has been updated.";
	} elseif ($_POST['action'] == 'add') {
		$objPic ->add();
		$msg = "msg=Banner has been added.";
	}
	
	$url = "feature.php?$msg";
	Tzn::redirect($url);
}

?>
<?php include("header.php"); ?>


<?php include("sidebar.php"); ?>
<ul id="subnav" >
	<li ><a class="back" href="feature.php" > Back </a></li>
	<li class="noborder" >
		<a class="add" href="<?php echo $_SERVER['PHP_SELF']?>" > Add a New Banner</a>
	</li>
</ul>
<div id="list">
<h2> <?php echo $pTitle;?> </h2>
<form action="" method="post" name = "frmMain" id = "frmMain"  enctype="multipart/form-data"    >
 <fieldset><legend> Banner Info </legend>
  <table cellpadding="0" cellspacing="0" class="table-form" width="520px">
  	<tr>
	 <th width="12%"  >Title: </th>
	 <td width="88%" ><?php $objPic ->qText('title', '', 'width:280px', 'class=""');?></td>
	</tr>
	   <tr>
	 	<th>Picture: </th>
	 	<td>
	 	<?php
	 		if (! $objPic ->path) {
	 			Tzn::qFile('ifile');
	 		} else { ?>
	 		<div class="img-border" style="width: 130px;" >
	 		 <?php echo $objPic ->getImage()  ?><br/>
	 		 	<a title="Delete Image" href="<?php echo $_SERVER['PHP_SELF'].'?action=del&id='. $objPic->id ?>"> <b>(x) delete </b> </a>
	 		</div>	
		<?php 	 			
	 		}
	 	?>
	 	</td>  
	   </tr>
	   
	
	<tr>
	 <th>Status: </th>
	 <td><?php 
	 	$objCollection = new TznCollection(array('Live' => 'Live', 'Draft' => 'Draft'));
		$objCollection->qSelect('status', $objPic ->status, false, 'width:142px;');
	  ?></td>
  </tr>
	</table>
 </fieldset>
 <div style="margin-top:10px">
				<input type="hidden" name="action" value="<?php echo $action; ?>" />
                <input type="submit" name="submit"  value="<?php echo $pButton; ?>" /> &nbsp;
                <input type="reset" value="Cancel" onClick="window.location.href='feature.php' " />
 </div>
</form>
</div>
<?php include("footer.php"); ?>
